<script lang="tsx" setup>
import { NButton } from 'naive-ui';
import { toRefs } from 'vue';
import { getPageList } from '@/service/api/developer/config';
import { useTable, useTableOperate } from '@/hooks/common/table';
import { useAppStore } from '@/store/modules/app';
import { $t } from '@/locales';
import { useDict } from '@/utils/dict';
import DictTag from '@/components/custom/dict-tag.vue';
import ConfigSearch from './components/config-search.vue';
const { sys_yes_no } = toRefs<any>(useDict('sys_yes_no'));
const appStore = useAppStore();

const { columns, columnChecks, data, getData, loading, mobilePagination, searchParams, resetSearchParams } = useTable({
  apiFn: getPageList,
  showTotal: true,
  apiParams: {
    pageNum: 1,
    pageSize: 10,
    configName: null,
    configKey: null,
    configType: null
  },
  columns: () => [
    {
      type: 'selection',
      align: 'center',
      width: 48
    },
    {
      key: 'configName',
      title: '参数名称',
      align: 'center',
      minWidth: 100
    },
    {
      key: 'configKey',
      title: '参数键名',
      align: 'center',
      minWidth: 100
    },
    {
      key: 'configValue',
      title: '参数键值',
      align: 'center',
      minWidth: 100
    },
    {
      key: 'configType',
      title: '是否内置',
      align: 'center',
      minWidth: 100,
      render: row => {
        return <DictTag type="tag" value={row.configType} dicts={sys_yes_no.value} />;
      }
    },
    {
      key: 'remark',
      title: '备注',
      align: 'left',
      minWidth: 100,
      ellipsis: {
        tooltip: true
      }
    },
    // {
    //   key: 'status',
    //   title: '状态',
    //   align: 'center',
    //   minWidth: 100,
    // render: row => {
    //   return <DictTag type="badge" value={row.status} dicts={sys_normal_disable.value} />;
    // }
    // },
    {
      key: 'operate',
      title: $t('common.operate'),
      align: 'center',
      fixed: 'right',
      width: 130,
      render: row => (
        <div class="flex-center gap-8px">
          <NButton type="primary" ghost size="small" onClick={() => {}}>
            {$t('common.edit')}
          </NButton>
        </div>
      )
    }
  ]
});
const {
  drawerVisible,
  operateType,
  editingData,
  handleAdd,
  handleEdit,
  checkedRowKeys,
  onBatchDeleted,
  onDeleted
  // closeDrawer
} = useTableOperate(data, getData);
</script>

<template>
  <div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
    <ConfigSearch v-model:model="searchParams" :sys-yes-no="sys_yes_no" @reset="resetSearchParams" @search="getData" />
    <NCard title="系统配置" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
      <template #header-extra>
        <TableHeaderOperation
          v-model:columns="columnChecks"
          :disabled-delete="checkedRowKeys.length === 0"
          :loading="loading"
          @add="handleAdd"
          @refresh="getData"
        />
      </template>
      <NDataTable
        v-model:checked-row-keys="checkedRowKeys"
        :columns="columns"
        :data="data"
        size="small"
        :flex-height="!appStore.isMobile"
        :scroll-x="962"
        :loading="loading"
        remote
        :row-key="row => row.configId"
        :pagination="mobilePagination"
        class="sm:h-full"
      >
        <template #empty>
          <Empty />
        </template>
      </NDataTable>
    </NCard>
  </div>
</template>

<style scoped></style>
